<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="接受资料邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receivedArchivesEmail">
              <a-input v-model="model.receivedArchivesEmail" placeholder="请输入接受资料邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单状态：0-待支付、1-待发货、2-待收货、3-已完成 、4-已取消" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderStatus">
              <a-input-number v-model="model.orderStatus" placeholder="请输入订单状态：0-待支付、1-待发货、2-待收货、3-已完成 、4-已取消" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderId">
              <a-input v-model="model.orderId" placeholder="请输入订单ID" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="买家ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="buyerId">
              <a-input v-model="model.buyerId" placeholder="请输入买家ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资料ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="libraryId">
              <a-input v-model="model.libraryId" placeholder="请输入资料ID" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="店铺ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopId">
              <a-input v-model="model.shopId" placeholder="请输入店铺ID" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下单时主图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cover">
              <a-input v-model="model.cover" placeholder="请输入下单时主图"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="店铺名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopName">
              <a-input v-model="model.shopName" placeholder="请输入店铺名" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预览文件URL" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="previewArchiveUrl">
              <j-upload v-model="model.previewArchiveUrl"  disabled ></j-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资料文件URL" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archiveUrl">
              <j-upload v-model="model.archiveUrl"   ></j-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资料名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archiveName">
              <a-input v-model="model.archiveName" placeholder="请输入资料名称" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下单时商品价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="retailPrice">
              <a-input-number v-model="model.retailPrice" placeholder="请输入下单时商品价格" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quantity">
              <a-input-number v-model="model.quantity" placeholder="请输入数量" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HTOrderLibraryForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           receivedArchivesEmail: [
              { required: true, message: '请输入接受资料邮箱!'},
           ],
           orderStatus: [
              { required: true, message: '请输入订单状态：0-待支付、1-待发货、2-待收货、3-已完成 、4-已取消!'},
           ],
           orderId: [
              { required: true, message: '请输入订单ID!'},
           ],
           buyerId: [
              { required: true, message: '请输入买家ID!'},
           ],
           libraryId: [
              { required: true, message: '请输入资料ID!'},
           ],
           shopId: [
              { required: true, message: '请输入店铺ID!'},
           ],
           cover: [
              { required: true, message: '请输入下单时主图!'},
           ],
           shopName: [
              { required: true, message: '请输入店铺名!'},
           ],
           previewArchiveUrl: [
              { required: true, message: '请输入预览文件URL!'},
           ],
           archiveUrl: [
              { required: true, message: '请输入资料文件URL!'},
           ],
           archiveName: [
              { required: true, message: '请输入资料名称!'},
           ],
           retailPrice: [
              { required: true, message: '请输入下单时商品价格!'},
           ],
           quantity: [
              { required: true, message: '请输入数量!'},
           ],
        },
        url: {
          add: "/order/hTOrderLibrary/add",
          edit: "/order/hTOrderLibrary/edit",
          queryById: "/order/hTOrderLibrary/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>